//
//  CXHomeController.swift
//  XinaWeibo
//
//  Created by chenxuan on 2017/4/4.
//  Copyright © 2017年 chenxuan. All rights reserved.
//

import UIKit

class CXHomeController: CXBaseViewController {

    /// 列表视图模型
    fileprivate lazy var listViewModel = CXStatusListViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        loadData()
        // Do any additional setup after loading the view.
    }
    
    func showFriends() {
        let vc = CXTestViewController()
        navigationController?.pushViewController(vc, animated: true)
    }
    
    override func loadData() {
        
        listViewModel.loadStatus { (isSuccess) in
            
            // 结束刷新控件
            self.refreshControl?.endRefreshing()
            // 恢复上拉刷新标记
            self.isPullup = false
            // 刷新表格
            self.tableView?.reloadData()
        }
        
    
    }
}

extension CXHomeController {
    override func setupTableView() {
        super.setupTableView()
        // 设置导航栏按钮
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
    }
}


extension CXHomeController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listViewModel.statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cellid")
        if cell == nil {
            cell = UITableViewCell()
        }
        cell?.textLabel?.text = listViewModel.statusList[indexPath.row].text
        return cell!
    }
    
}
